<?php
namespace Common\Model;

class AderServiceModel extends UserModel {
    const TYPE = 4; //4表示广告主客服

    public function save2($d) {
        $d['type'] = self::TYPE;
        $d['recommend_income_scale'] = empty($d['recommend_income_scale']) ? 0 : (float)$d['recommend_income_scale'];  //广告主客服提成

        try {
            return parent::save2($d);
        } catch(Exception $e) {
            throw new ThinkException($e->getMessage());
        }
    }

    public function getByUid($uid) {
        $expr = array(
            'type' => self::TYPE,
            'uid'  => $uid,
        );

        return $this->where($expr)->find();
    }

    /**
     * del
     *
     * @param mixed $id
     * @return void
     */
    public function del($id) {
        $id = (int)$id;

        $expr = array(
            'type' => self::TYPE,
            'uid'  => $id,
        );

        return $this->where($expr)->delete();
    }

    protected function _options_filter(&$options) {
        $options['where']         = isset($options['where']) ? $options['where'] : array();
        $options['where']['type'] = self::TYPE;
    }

}
